package com.zjun.demo.experimentaldemo.thread_lock

import android.util.Log
import android.view.View
import com.bumptech.glide.Glide
import com.zjun.demo.experimentaldemo.R
import com.zjun.demo.experimentaldemo.base.BaseActivity
import com.zjun.demo.experimentaldemo.databinding.ActivityJavaLockBinding
import java.lang.Thread.sleep
import java.util.concurrent.atomic.AtomicInteger
import kotlin.concurrent.thread

/**
 *
 *
 */
class ThreadLockActivity : BaseActivity<ActivityJavaLockBinding>() {

    private var mLock1 = Object()

    private var mLock2 = Object()

    private var count = 0

    private var mIsGetAwsCallEvent: AtomicInteger? = AtomicInteger(-1)

    override fun getLayoutId(): Int = R.layout.activity_java_lock

    override fun initialize() {

    }

    fun setNull(view: View) {
        mIsGetAwsCallEvent = null
    }

    fun setImage1(view: View) {
        Glide.with(mBinding.imageView3)
            .load("https://usecampic.efercro.com/60d/S14G250001000008/1744976643041-4.jpg")
            .into(mBinding.imageView3)
    }

    fun setImage2(view: View) {
        Glide.with(mBinding.imageView3)
            .load("https://usecampic.efercro.com/60d/S14G250001000008/1744976724193-4.jpg")
            .into(mBinding.imageView3)
    }





    fun multiThreadedTesting(view: View) {
        thread {
            mIsGetAwsCallEvent?.run {
                sleep(5000)
                synchronized(this){
                    mIsGetAwsCallEvent
                }
            }
        }

//        var sdf = mIsGetAwsCallEvent
//        mIsGetAwsCallEvent = null
//
//        thread {
//            synchronized(mLock1){
//                for(i in 0..50){
//                    count += 1
//                    Log.i("线程测试", "线程1 ${count} ")
//                    sleep(500)
//                }
//            }
//        }
//        thread {
//            sleep(5000)
//        }
    }

    override fun onDestroy() {
        super.onDestroy()
        synchronized(mLock1) {
            Log.i("线程测试", "onDestroy ${count} ")
        }
    }



}